/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function (nums, target) {
  //数组长度
  let len = nums.length;
  // 左窗口边界
  let i = 0;
  // 右窗口边界
  let j = len - 1;
  // 找右边界
  while (i <= j) {
    let middle = i + Math.floor((j - i) / 2);
    if (nums[middle] <= target) {
      i = middle + 1;
    } else {
      j = middle - 1;
    }
  }
  let right = i;
  i = 0;
  j = len - 1;
  while (i <= j) {
    let middle = i + Math.floor((j - i) / 2);
    if (nums[middle] >= target) {
      j = m - 1;
    } else {
      i = m + 1;
    }
  }
  let left = i;
  console.log(left, right);
};
